package models

import (
	"course-srv/basic/config"
	"gorm.io/gorm"
)

// 收藏表
type Collect struct {
	gorm.Model
	UserId   int `gorm:"type:int;comment:'用户id'"`
	CourseId int `gorm:"type:int;comment:'课程id'"`
}

func (cc *Collect) TableName() string {
	return "collect"
}

// 添加收藏
func (cc *Collect) AddCollect() error {
	return config.DB.Create(&cc).Error
}

// 我的收藏列表
func (cc *Collect) GetCollectList(userId int) (collectList []*Collect, err error) {
	config.DB.Model(&Collect{}).Where("user_id = ?", userId).Find(&collectList)
	return collectList, err
}

// 收藏详情
func (cc *Collect) GetCollectDetail(userId int) error {
	return config.DB.Model(&Collect{}).Where("user_id = ?", userId).Limit(1).Find(&cc).Error
}
